# Copyright (c) 2023, json_wang and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document
from urllib.parse import quote,quote_plus  

class wxwork_setting(Document):
	pass

	def before_save(self):
		full_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='
		full_url += self.corpid
		full_url += '&redirect_uri='
		redirect_url = self.base_url + '/api/method/wxwork_en.wxwork_for_erpnext.wxwork_service.wxwork_login'
		redirect_url_encode = quote_plus(redirect_url)
		full_url += redirect_url_encode
		full_url += '&response_type=code&scope=snsapi_base&state=STATE&agentid='
		full_url += self.app_agentid
		full_url += '#wechat_redirect'
		self.wx_homepage = full_url
